package T01;
//定义一个Student类，属性：姓名、性别、年龄。
// 在性别的set方法中判断是否是男/女，
//        如果不是则抛出：性别异常
//在年龄的set方法中判断年龄是否是15--50之间，
//        如果不是则抛出：年龄异常
public class Student {
    private String name;
    private char sex;
    private int age;

    public Student() {
    }

    public Student(String name, char sex, int age) {
        this.name = name;
        this.sex = sex;
        this.age = age;
    }



    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }


    public void setSex(Character sex) throws SexException{
        if (sex.equals('男') || sex.equals('女')){

            System.out.println("年龄正常");
            this.sex = sex;

        }else {
            throw new SexException("/sex is Exception,your sex is" + sex + "性别错误");
        }

    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) throws AgeException{
        if (age>=15 && age <=50){
            System.out.println("年龄正常（15-50岁）："+age);
            this.age = age;
        }else {
            //用年龄异常对象封装这个问题
            //throw 抛出去这个异常问题
            throw new AgeException("/age is Exception,your age is"+age+"：年龄异常");
        }

    }


}
